package com.fare.taluo.core.domain.config.channel.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.dayatang.hibernate.EntityRepositoryHibernate;
import com.fare.taluo.core.domain.config.channel.AirCompanyEntity;
import com.fare.taluo.core.domain.config.channel.AirCompanyEntityReposity;

@Repository
public class AirCompanyEntityRepositoryImpl  extends EntityRepositoryHibernate implements AirCompanyEntityReposity{

	@Override
	public List<AirCompanyEntity> all() {
		List<AirCompanyEntity> airCompanyEntities = super.findAll(AirCompanyEntity.class);
		return airCompanyEntities;
	}

	@Override
	public AirCompanyEntity findCompanNameByCode(String code) {
		List<Object> params = new ArrayList<Object>();
		String hql = "from AirCompanyEntity entity where  1=1 ";
		if (code != null) {
			hql += " and entity.company_code= ? ";
			params.add(code);
		}
		List<AirCompanyEntity> entityList = super.find(hql.toString(), params.toArray(), AirCompanyEntity.class);
		AirCompanyEntity entity=new AirCompanyEntity();
		if(entityList.size()>0){
			entity=entityList.get(0);
		}
		return entity;
	}

	@Override
	public AirCompanyEntity findCompanCodeByName(String name) {
		List<Object> params = new ArrayList<Object>();
		String hql = "from AirCompanyEntity entity where  1=1 ";
		if (name != null) {
			hql += " and entity.name= ? ";
			params.add(name);
		}
		List<AirCompanyEntity> entityList =super.find(hql, params.toArray(), AirCompanyEntity.class);
		AirCompanyEntity entity=new AirCompanyEntity();
		if(entityList.size()>0){
			entity=entityList.get(0);
		}
		return entity;
	}

	
}
